package com.markbuikema.juliana32.model.teams;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.markbuikema.juliana32.enums.CompType;
import com.markbuikema.juliana32.enums.GameType;

public class League {

	private List<GameEvent> pastGames;
	private List<GameEvent> upcomingGames;
	private List<Table> tables;
	private String compName;
	private String compId;
	private String className;
	private String classId;
	private String pouleName;
	private String pouleId;
	private String district;
	private CompType type;

	public League(String name, String id, String className, String classId, String pouleName, String pouleId, String district, CompType type) {
		pastGames = new ArrayList<GameEvent>();
		upcomingGames = new ArrayList<GameEvent>();
		tables = new ArrayList<Table>();

		this.compName = name;
		this.compId = id;
		this.className = className;
		this.classId = classId;
		this.pouleName = pouleName;
		this.pouleId = pouleId;
		this.district = district;
		this.type = type;
	}

	public void addTable(Table table) {
		tables.add(table);
	}

	public void addPastGames(List<GameEvent> games) {
		pastGames.addAll(games);
		Collections.sort(pastGames);
		Collections.reverse(pastGames);
	}

	public void addUpcomingGames(List<GameEvent> games) {
		for (GameEvent game : games) {
			boolean contains = false;
			for (GameEvent pastGame : pastGames) {
				if (pastGame.getGameNumber().equals(game.getGameNumber())) {
					contains = true;
				}
			}
			if (!contains)
				upcomingGames.add(game);
		}
		Collections.sort(upcomingGames);
	}

	public List<GameEvent> getGames(GameType time) {
		switch (time) {
		case PAST:
			return pastGames;
		case UPCOMING:
		default:
			return upcomingGames;
		}
	}

	public List<Table> getTables() {
		return tables;
	}

	public String getCompName() {
		return compName;
	}

	public String getCompId() {
		return compId;
	}

	public String getClassName() {
		return className;
	}

	public String getClassId() {
		return classId;
	}

	public String getPouleName() {
		return pouleName;
	}

	public String getPouleId() {
		return pouleId;
	}

	public String getDistrict() {
		return district;
	}

	public CompType getType() {
		return type;
	}

}
